package com.os.opencv.java.chapter7;

import org.opencv.core.*;
import org.opencv.imgproc.Imgproc;

public class HitMiss {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        //构建一个6*6的小矩阵并手工导入数据
        Mat src = new Mat(6,6, CvType.CV_8UC1);
        byte[] data = new byte[]{
                0,0,0,0,0,0,
                0,0,1,1,1,0,
                0,1,1,1,1,0,
                0,1,1,1,1,0,
                0,1,1,0,0,0,
                0,0,1,1,0,0
        };
        src.put(0,0,data);

        //在控制台输出矩阵，以便进行数据确认
        System.out.println(src.dump());
        System.out.println();

        //构建矩形结构元素并在控制台输出
        Mat kernel = Imgproc.getStructuringElement(0, new Size(3,3));
        System.out.println(kernel.dump());
        System.out.println();

        //击中击不中测试并在控制台输出
        Point anchor = new Point(-1,-1);
        Mat dst = new Mat(6,6,CvType.CV_8UC1);
        Imgproc.morphologyEx(src, dst, Imgproc.MORPH_HITMISS, kernel, anchor, 1);

        System.out.println(dst.dump());

    }
}
